package main

import "sort"

var result [][]int

func subsetsWithDup(nums []int) [][]int {
	result = nil
	sort.Ints(nums)
	backtrack(nums, []int{}, 0)
	return result
}

func backtrack(nums []int, list []int, pos int) {
	item := make([]int, len(list))
	copy(item, list)
	result = append(result, item)
	for i := pos; i < len(nums); i++ {
		if i != pos && nums[i] == nums[i-1] {
			continue
		}
		list = append(list, nums[i])
		backtrack(nums, list, i+1)
		list = list[0 : len(list)-1]
	}
}

func main() {
	re := subsetsWithDup([]int{1, 1, 2, 3})
	println(re)
}
